package com.ruoyi.mp.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.mp.domain.MpMessage;
import com.ruoyi.mp.service.IMpMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 公众号消息 Controller
 * 
 * @author 郎兴宇
 * @date 2024-11-29 18:42
 */
@RestController
@RequestMapping("/message")
public class MpMessageController extends BaseController
{
    @Autowired
    private IMpMessageService mpMessageService;

    /**
     * 查询公众号消息 列表
     */
    @RequiresPermissions("mp:message:list")
    @GetMapping("/list")
    public TableDataInfo list(MpMessage mpMessage)
    {
        startPage();
        List<MpMessage> list = mpMessageService.selectMpMessageList(mpMessage);
        return getDataTable(list);
    }

    /**
     * 导出公众号消息 列表
     */
    @RequiresPermissions("mp:message:export")
    @Log(title = "公众号消息 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MpMessage mpMessage)
    {
        List<MpMessage> list = mpMessageService.selectMpMessageList(mpMessage);
        ExcelUtil<MpMessage> util = new ExcelUtil<MpMessage>(MpMessage.class);
        util.exportExcel(response, list, "公众号消息 数据");
    }

    /**
     * 获取公众号消息 详细信息
     */
    @RequiresPermissions("mp:message:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mpMessageService.selectMpMessageById(id));
    }

    /**
     * 新增公众号消息 
     */
    @RequiresPermissions("mp:message:add")
    @Log(title = "公众号消息 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MpMessage mpMessage)
    {
        return toAjax(mpMessageService.insertMpMessage(mpMessage));
    }

    /**
     * 修改公众号消息 
     */
    @RequiresPermissions("mp:message:edit")
    @Log(title = "公众号消息 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MpMessage mpMessage)
    {
        return toAjax(mpMessageService.updateMpMessage(mpMessage));
    }

    /**
     * 删除公众号消息 
     */
    @RequiresPermissions("mp:message:remove")
    @Log(title = "公众号消息 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mpMessageService.deleteMpMessageByIds(ids));
    }
}
